var t = getApp();

Page({
    data: {
        name: "",
        tabs: [],
        selected: 0,
        tabID: 0,
        bossList: [],
        detail: {},
        uid: 0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        searchMember: "",
        isSearch: !1
    },
    searchMemberval: function(t) {
        var a = t.detail;
        this.getData({
            searchMember: a,
            isSearch: !0
        });
    },
    onLoad: function(t) {
        this.getTab();
    },
    onReady: function() {},
    onShow: function() {
        var t = this;
        wx.getStorage({
            key: "yz_basic_info",
            success: function(a) {
                console.log(a), setTimeout(function() {
                    t.setData({
                        name: a.data.lang.team_dividend && a.data.lang.team_dividend.my_agent ? a.data.lang.team_dividend.my_agent : "我的客户"
                    }), wx.setNavigationBarTitle({
                        title: t.data.name
                    });
                }, 2e3);
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        1 == this.data.isLoadMore && (console.log("进"), this.data.page < this.data.total_page ? (this.setData({
            page: this.data.page + 1,
            isLoadMore: !0
        }), wx.showLoading({
            title: "加载中"
        }), this.getMore()) : this.data.page >= this.data.total_page && this.setData({
            isLoadMore: !1
        }));
    },
    onShareAppMessage: function() {},
    showDetail: function(a) {
        var e = this, s = a.target.dataset.item || a.currentTarget.dataset.item;
        if (s.show && this.data.uid === s.has_one_member.uid) {
            for (var i = this.data.bossList, o = 0; o < i.length; o++) i[o].id == s.id && (i[o].show = !1);
            this.setData({
                bossList: i
            });
        } else {
            this.setData({
                uid: s.has_one_member.uid
            });
            var n = t.getNetAddresss("plugin.team-dividend.api.team.getInfo");
            n += "&uid=" + s.has_one_member.uid, t._getNetWork({
                url: n,
                success: function(t) {
                    var a = t.data;
                    if (1 === a.result) {
                        e.setData({
                            detail: a.data
                        });
                        for (var i = e.data.bossList, o = 0; o < i.length; o++) i[o].id == s.id && (i[o].show = !0);
                        e.setData({
                            bossList: i
                        });
                    } else wx.showToast({
                        title: a.msg,
                        icon: "none"
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    getTab: function() {
        var a = this, e = t.getNetAddresss("plugin.team-dividend.api.team.getColumns");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 === e.result ? (a.setData({
                    tabs: e.data.columns,
                    tabID: e.data.columns[0].id
                }), a.getData()) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    changeTab: function(t) {
        var a = t.target.dataset.item || t.currentTarget.dataset.item, e = t.target.dataset.index || t.currentTarget.dataset.index;
        this.setData({
            selected: e,
            tabID: a.id
        }), this.getData();
    },
    getData: function(a) {
        var e = this;
        this.setData({
            page: 1,
            isLoadMore: !1
        });
        var s = t.getNetAddresss("plugin.team-dividend.api.team.getList");
        s += "&id=" + this.data.tabID, a && (s += "&member_info=" + a), t._getNetWork({
            url: s,
            success: function(t) {
                var a = t.data;
                1 === a.result ? e.setData({
                    bossList: a.data.list.data,
                    isLoadMore: !0,
                    total_page: a.data.list.last_page
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMore: function() {
        var a = this;
        this.setData({
            page: this.data.page
        });
        var e = t.getNetAddresss("plugin.team-dividend.api.team.getList");
        e += "&id=" + this.data.tabID, this.data.isSearch && (e += "&member_info" + this.data.searchMember), 
        t._getNetWork({
            url: e,
            data: {
                page: this.data.page
            },
            success: function(t) {
                var e = t.data;
                1 === e.result ? (wx.hideLoading(), a.setData({
                    bossList: a.data.bossList.concat(e.data.list.data),
                    isLoadMore: !0,
                    total_page: e.data.list.last_page
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});